package com.study.service;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.study.parse.TestParser;

public class TestService {
	
	private MsgProcessor mp;

    public void init(){
        this.mp = new MsgProcessor();
        ParseChain pc = new ParseChain();
        pc.addFilter(new TestParser());
        this.mp.setPc(pc);
    }

    public String parse(String message) {
        JSONObject msg = null;
        try {
            msg = JSONObject.parseObject(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (msg == null)
            return message;
        if (!StringUtils.isBlank(message)) {
            String result = this.mp.process(message);
            return result;
        } else {
            return "无效的数据或者过滤掉了";
        }
    }

}
